﻿using Ndns.Packet.Abstractions;
using System.Collections.Generic;
using System.IO;

namespace Ndns.Packet.Parser
{
    static class DnsQueryExtensions
    {
        public static int CopyTo(this DnsQuery query, Stream stream, ref int offset)
        {
            int count;
            count = query.HostName.CopyTo(stream, ref offset);
            stream.WriteNetworkUInt16((ushort)query.Type);
            stream.WriteNetworkUInt16((ushort)query.Class);
            offset += 4;
            return count + 4;

        }

        public static int CopyCompressedTo(this DnsQuery query, Stream stream, IDictionary<string, DnsHostNamePointer> symbols, ref int offset)
        {
            int count;
            count = query.HostName.CopyCompressedTo(stream, symbols, ref offset);
            stream.WriteNetworkUInt16((ushort)query.Type);
            stream.WriteNetworkUInt16((ushort)query.Class);
            offset += 4;
            return count + 4;
        }
    }
}
